from django.db import models
from users.models import User

class ProjectType(models.Model):
    name = models.CharField(max_length=50, verbose_name='项目类型')
    def __str__(self):
        return self.name

class Project(models.Model):
    number = models.CharField(max_length=20, verbose_name='项目编号')
    name = models.CharField(max_length=100, verbose_name='项目名称')
    type = models.ForeignKey(ProjectType, on_delete=models.CASCADE, verbose_name='项目类型')
    start_date = models.DateField(verbose_name='立项日期')
    image = models.ImageField(upload_to='projects/', null=True, blank=True, verbose_name='项目图片')
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='申报人')
    content = models.TextField(verbose_name='立项内容', blank=True)
    status = models.CharField(max_length=20, verbose_name='项目状态', blank=True)
    budget = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='项目预算', default=0)
    cost = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='项目费用', default=0)
    progress = models.CharField(max_length=20, verbose_name='完成进度', blank=True)
    end_date = models.DateField(null=True, blank=True, verbose_name='结项日期')

    def __str__(self):
        return self.name

class ProjectVote(models.Model):
    project = models.ForeignKey(Project, on_delete=models.CASCADE, related_name='votes')
    voter = models.ForeignKey(User, on_delete=models.CASCADE)
    vote_time = models.DateTimeField(auto_now_add=True)

class ProjectAttachment(models.Model):
    project = models.ForeignKey(Project, on_delete=models.CASCADE, related_name='attachments')
    file = models.FileField(upload_to='attachments/')
    uploaded_at = models.DateTimeField(auto_now_add=True) 